package com.llkj.contractmanagement.customview;

import android.app.ActionBar;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.llkj.contractmanagement.R;
import com.llkj.contractmanagement.utils.SendEmailUtils;
import com.llkj.contractmanagement.utils.ToastUtil;


/**
 * Created by lanling-android on 2016/1/8.
 * 分享对话框
 */
public class ShareDialog extends Dialog {

    private RelativeLayout rlDown;
    private RelativeLayout rlWechat;
    private RelativeLayout rlQQ;
    private RelativeLayout rlEmail;
    private Context context = null;
    private Button txt_cancel;
    private ShareOnItemClickListener shareOnItemClickListener;

    public ShareOnItemClickListener getShareOnItemClickListener() {
        return shareOnItemClickListener;
    }

    public void setShareOnItemClickListener(ShareOnItemClickListener shareOnItemClickListener) {
        this.shareOnItemClickListener = shareOnItemClickListener;
    }

    public ShareDialog(Context context) {
        this(context, R.style.ActionSheetDialogStyle);
    }

    public ShareDialog(Context context, int theme) {
        super(context, theme);
        this.context = context;
        init(context);
    }

    private void init(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_dialog_bg, null);
        setContentView(view);
        initView(view);
        initListener();
    }

    private void initListener() {
        rlDown.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (shareOnItemClickListener != null) {
                    shareOnItemClickListener.down();
                }
            }
        });
        rlWechat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (shareOnItemClickListener != null) {
                    shareOnItemClickListener.shareWeChat();
                }
            }
        });

        rlQQ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (shareOnItemClickListener != null) {
                    shareOnItemClickListener.shareQQ();
                }
            }
        });
        rlEmail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                SendEmailUtils.getInstance().sendEmail(getContext());
                if (shareOnItemClickListener != null) {
                    shareOnItemClickListener.email();
                }
            }

        });
        txt_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();

            }
        });

    }

    private void initView(View view) {
        txt_cancel = (Button) view.findViewById(R.id.btn_share_cancel);
        rlDown = (RelativeLayout) view.findViewById(R.id.rl_share_down);
        rlWechat = (RelativeLayout) view.findViewById(R.id.rl_share_wechat);
        rlQQ = (RelativeLayout) view.findViewById(R.id.rl_share_qq);
        rlEmail = (RelativeLayout) view.findViewById(R.id.rl_share_email);
        Window window = getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.gravity = Gravity.BOTTOM;
        lp.width = ActionBar.LayoutParams.MATCH_PARENT;
        lp.x = 0;
        lp.y = 0;
        window.setAttributes(lp);
    }

    public interface ShareOnItemClickListener {
        void down();

        void shareQQ();

        void shareWeChat();

        void email();
    }
}
